#include "CMainMenuState.h"

#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_DirectInput.h"

#include "CGame.h"
#include "CGamePlayState.h"
#include "COptionsState.h"
#include "CHowToPlayState.h"

CMainMenuState::CMainMenuState(void)
{
	m_sMenuIndex = 0;
	m_nMenuCursor = -1;
	m_BMFonts.SetImageID(CSGD_TextureManager::GetInstance()->LoadTexture("resources/graphics/AnG_bitmapfont.png", D3DXCOLOR(0,255,0,255)));
	m_BMFonts.SetCharWidth(8);
	m_BMFonts.SetCharHeight(9);
	m_BMFonts.SetCol(16);
	m_BMFonts.SetStartChar('@');
}


CMainMenuState::~CMainMenuState(void)
{

} 

CMainMenuState* CMainMenuState::GetInstance(void)
{
	static CMainMenuState instance;
	return &instance;
}

void CMainMenuState::Enter(void)
{
	m_sMenuIndex = 0;

	m_nMenuCursor = CSGD_TextureManager::GetInstance()->LoadTexture("resources/graphics/SGD_MenuCursor.png", D3DCOLOR_XRGB(255, 255, 255));
}

bool CMainMenuState::Input(void)
{
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();
	
	if(pDI->KeyPressed(DIK_UPARROW))
	{
		if(--m_sMenuIndex < 0)
			m_sMenuIndex = 3;
	}
	else if(pDI->KeyPressed(DIK_DOWNARROW))
		if(++m_sMenuIndex > 3)
			m_sMenuIndex = 0;

	if(pDI->KeyPressed(DIK_RETURN))
	{
		if(m_sMenuIndex == 0)
			CGame::GetInstance()->ChangeState(CGamePlayState::GetInstance());
		else if(m_sMenuIndex == 1)
			CGame::GetInstance()->ChangeState(COptionsState::GetInstance());
		else if(m_sMenuIndex == 2)
			CGame::GetInstance()->ChangeState(CHowToPlayState::GetInstance());
		else if(m_sMenuIndex == 3)
			return true;
	}
		
	return false;
}

void CMainMenuState::Update(float fElapsedTime)
{

}

void CMainMenuState::Render(void)
{
	CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance();

	pD3D->Clear(0, 0, 0);
	pD3D->DeviceBegin();

	pD3D->SpriteBegin();

	CSGD_TextureManager::GetInstance()->Draw(m_nMenuCursor, 80,200 + (m_sMenuIndex * 33)); //, 4.0f, 4.0f, NULL, 64.0f, 65.0f, 0, D3DCOLOR_ARGB(128, 255, 0, 0));
	m_BMFonts.Draw("STICKBRAH", 100,100, 1.0f, D3DXCOLOR(255,255,255,255));
	m_BMFonts.Draw("PLAY", 100,200, 1.0f, D3DXCOLOR(255,255,255,255));
	m_BMFonts.Draw("OPTIONS", 100,233, 1.0f, D3DXCOLOR(255,255,255,255));
	m_BMFonts.Draw("HOW TO PLAY", 100,266, 1.0f, D3DXCOLOR(255,255,255,255));
	m_BMFonts.Draw("QUIT", 100,300, 1.0f, D3DXCOLOR(255,255,255,255));

	pD3D->SpriteEnd();

	pD3D->DeviceEnd();
	/*pD3D->DrawText("stickBrah", 100, 100);
	pD3D->DrawText("Play", 100, 200);
	pD3D->DrawText("Options",100,233);
	pD3D->DrawText("How to Play",100,266);
	pD3D->DrawText("Quit", 100, 300);*/

	pD3D->Present();
}

void CMainMenuState::Exit(void)
{
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	pTM->UnloadTexture(m_nMenuCursor);

}